﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Admin_Article_IframUpLoad : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string imgs = "picPath";
        if (Request.QueryString["img"] != null)
        {
            imgs = Request.QueryString["img"].ToString();
        }

        if (FileUpload1.PostedFile != null)
        {
            string Url = "Upload/Article/";
            string filename;//文件名字
            string hz;
            string newname;
            filename = FileUpload1.FileName;
            //取后最
            int pos = filename.IndexOf(".");
            hz = filename.Substring((pos + 1)).ToLower();

            if (hz != "gif" && hz != "jpg" && hz != "jpeg" && hz != "bmp")
            {

                Response.Write("<script>alert('图片只支持－－－gif|jpg|jpeg|bmp');location.href='IframUpLoad.aspx?img=" + imgs + "';</script>");
                Response.End();

            }
            newname = sjname() + "." + hz;
            //保存图片
            string pathurl;
            pathurl = Server.MapPath("~/") + Url + newname;
            string kb = FileUpload1.FileContent.Length.ToString();

            FileUpload1.PostedFile.SaveAs(pathurl);
            Response.Write("<script>parent.document.form1." + imgs + ".value='" + Url + newname + "';</script>");
        }
    }
    /// <summary>
    /// 产生个随即名称
    /// </summary>
    /// <returns></returns>
    public string sjname()
    {

        string sj = null;
        sj = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.Hours.ToString() + DateTime.Now.TimeOfDay.Minutes.ToString() + DateTime.Now.TimeOfDay.Milliseconds.ToString();
        return sj;

    }
}
